<template>
	<div class="back_contain_n">
		<!-- 头部搜索 -->
		<div class="Search_Top_Part">
			<div class="search_list">
				<div>
					<div class="input_flex">
						<el-select clearable v-model="queryForm.whiteDay" placeholder="班次">
							<el-option label="白班" value="1"></el-option>
							<el-option label="夜班" value="2"></el-option>
						</el-select>
					</div>
					<div class="input_flex">
						<el-input clearable v-model="queryForm.processName" placeholder="工序"></el-input>
					</div>
					<div class="input_flex">
						<el-select clearable v-model="queryForm.abandonType" placeholder="废料类型">
							<el-option label="料头" value="1"></el-option>
							<el-option label="可回收" value="2"></el-option>
							<el-option label="不可回收" value="3"></el-option>
							<el-option label="彩膜" value="4"></el-option>
						</el-select>
					</div>
					<div class="input_flex">
						<el-input clearable v-model="queryForm.acceptMaterialUser" placeholder="收磅人"></el-input>
					</div>
					<div class="input_flex">
						<el-input clearable v-model="queryForm.sendMaterialUser" placeholder="送料人"></el-input>
					</div>
					<div class="input_flex daterange">
						<el-date-picker v-model="time" type="daterange"
										range-separator="-"
										start-placeholder="接收日期"
										end-placeholder="结束日期">
						</el-date-picker>
					</div>
				</div>
			</div>
			<div class="search_bt">
				<span class="zll-search" @click="getList">搜索</span>
				<span class="zll-search-reset" @click="searchReset()">重置</span>
			</div>
		</div>
		<!-- table -->
		<sys-table class="m_table"
				   ref="systable"
				   :isMultipleSelection="false"
				   :tableData="tableData"
				   :tableLoading="tableLoading"
				   :tableHeader="tableHeader"
				   :scopeWidth="120"
				   :backCount="backCount"
				   :isOperate="false"
				   @getBackData="getList"
		></sys-table>
	</div>
</template>

<script>
	import {formatDate} from "@/plugins/formatDate";

	export default {
		data() {
			return {
				queryForm: {
					whiteDay: '',
					processName: '',
					abandonType: '',
					sendMaterialUser: '',
					acceptMaterialUser: '',
					procureType: '',
				},
				backCount: 0,
				tableData: [],
				tableHeader: [],
				addDialog: false,
				tableLoading: false,
				time:[],
			}
		},
		methods: {
			getList(startIndex, pageRow) {
				let self = this;
				self.tableLoading = true;
				if (this.time && this.time.length == 2) {
					//date类型
					self.queryForm.startTime = formatDate(new Date(self.time[0]), 'yyyy-MM-dd')
					self.queryForm.endTime = formatDate(new Date(self.time[1]), 'yyyy-MM-dd') + ' 23:59:59'
				} else {
					self.queryForm.startTime = ''
					self.queryForm.endTime = ''
				}
				let pageInfo = self.$refs.systable.getPageInfo(startIndex);
				if (pageInfo.pageNum == 0 || startIndex == 0) {
					self.$refs.systable.resetPage();
				}
				self.queryForm.startIndex = pageInfo.pageNum;
				self.queryForm.totalPage = pageInfo.pageSize;
				let param = Object.assign({}, self.queryForm);
				self.$http({
					url: "/jinl/abandon/getAbandonMaterialList",
					method: "post",
					params:param
				}).then(resp => {
					if (resp.success) {
						self.tableLoading = false;
						self.tableData = resp.result;
						self.tableHeader = [
							{"columnValue": "abandonTime", "columnName": "废料日期"},
							{"columnValue": "whiteDayCn", "columnName": "班次"},
							{"columnValue": "processName", "columnName": "工序"},
							{"columnValue": "catetoryName", "columnName": "品类"},
							{"columnValue": "abandonTypeCn", "columnName": "废料类型"},
							{"columnValue": "weight", "columnName": "重量(kg)"},
							{"columnValue": "sendMaterialUser", "columnName": "送料人"},
							{"columnValue": "createTimeFt", "columnName": "接收时间"},
							{"columnValue": "acceptMaterialUser", "columnName": "收磅人"},
						];
						if (resp.result.length > 0) {
							self.backCount = resp.result[0].count;
						} else {
							self.backCount = 0;
						}
					}
				});

			},


			searchReset() { //重置搜索
				this.queryForm = {
					whiteDay: '',
					processName: '',
					abandonType: '',
					sendMaterialUser: '',
					acceptMaterialUser: '',
					procureType: '',
				};
				this.time = []
				this.getList();
			},
		},
		mounted() {
			let self = this;
			self.getList();
		},
	}
</script>

<style lang="scss" scoped>
	@import "@/style/SearchTop.scss";
</style>